<?php
function scan($url)
{
    //判断xray是否已经开启代理
    $cmd = "ps -ef | grep 7777 | grep -v grep";
    $ret = system($cmd);
    if (strlen($ret) == 0) {
        $cmd = "php startXray.php  > /tmp/xray.txt &";
        systemLog($cmd, $aa);
        sleep(5);
    }

    //启动RAD开始扫描
    file_put_contents("/tmp/url.txt", $url);
    $cmd = "php startRad.php > /tmp/rad.txt &";
    systemLog($cmd);

    //停止xray代理
    //$cmd = "kill -9 $(ps -ef |grep 7777 | grep -v grep | awk '{print $2}')";
    //systemLog($cmd);

    //重定向网址到首页
    redirect("http://{$_SERVER['host']}:{$_SERVER['port']}/");
}

function redirect($url)
{
    header("Location: $url");
    exit();
}

function systemLog($cmd, &$result = [])
{
    echo $cmd . PHP_EOL;
    system($cmd, $result);

    echo implode($result, "\n");
}

$url = $_POST['url'] ?? "http://hadskyh.test.com/index.php?c=list&";

scan($url);


